﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace planetExpressLib
{
    public class planetaCAD
    {
        SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\Dropbox\\HADA\\tortoise\\diseño_web_final\\planet_express\\App_Data\\PlanetExpressDB.mdf;Integrated Security=True;User Instance=True");

        public planetaEN insertPlanetaCAD(planetaEN p)
        {
            return null;
        }

        public void readPlanetaCAD(int idPlaneta)
        {

        }

        public void readPlanetaNomCAD(string nombre, planetaEN planeta)
        {
            //planetaEN planeta = new planetaEN();

            DataTable bdVirtual = new DataTable();
            string comando = "SELECT * FROM PLANETA WHERE (Nombre = '" + nombre + "')";
            SqlCommand cmd = new SqlCommand(comando, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(bdVirtual);


            planeta.Nombre = bdVirtual.Rows[0][1].ToString();

            string distancia_str = bdVirtual.Rows[0][3].ToString();
            planeta.Distancia = float.Parse(distancia_str);

            string masa_str = bdVirtual.Rows[0][4].ToString();
            planeta.Masa = float.Parse(masa_str);

            string radio_str = bdVirtual.Rows[0][5].ToString();
            planeta.Radio = float.Parse(radio_str);

            string periodo_str = bdVirtual.Rows[0][6].ToString();
            planeta.Periodo = float.Parse(periodo_str);
            

        }

        public void deletePlanetaCAD(int idPlaneta)
        {

        }

        public void updatePlanetaCAD(int idPlaneta)
        {

        }
        
        public DataTable gridviewPlaListaCAD(string nom_sist) {

            DataTable bdVirtual = new DataTable();
            string comando = "SELECT Nombre FROM PLANETA WHERE (Sistema = (SELECT Id FROM SISTEMA WHERE (Nombre = '"+nom_sist+"')))";
            SqlCommand cmd = new SqlCommand(comando, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(bdVirtual);

            return bdVirtual;
        }

        public DataTable gridviewPlaCadenaCAD(string nom_planeta){

            DataTable bdVirtual = new DataTable();
            string comando = "SELECT Nombre FROM PLANETA WHERE (nombre like '%"+nom_planeta+"%')";
            SqlCommand cmd = new SqlCommand(comando, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(bdVirtual);

            return bdVirtual;
        }

    }
}
